
package com.yunfei.api.product;
import com.google.gson.Gson;
import com.yunfei.bo.product.ProductInfoListForLiCaiShiBo;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.contants.ProductInfoContants;
import com.yunfei.contants.UserCenterContants;
import com.yunfei.enums.ResultStatus;
import com.yunfei.fegin.RedisService;
import com.yunfei.mapper.aiiidb.ProductInfoForLiCaiShiMapper;
import com.yunfei.utils.string.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 理财师产品列表相关接口
 * @Author: zhengyunfei
 * @Date: 2018/6/15
 * @time:11:26
 */
@Api(value = UserCenterContants.LICAISHI_PRODUCT_LIST_API_NAMESPACE,tags = UserCenterContants.LICAISHI_PRODUCT_LIST_API_NAMESPACE )
@RestController
@RequestMapping("/api/v2/liCaiShi/product")
public class ProductListForLiCaiShiApiController {
    @Autowired
    private RedisService redisService;
    @Autowired
    private ProductInfoForLiCaiShiMapper productInfoForLiCaiShiMapper;
    @Autowired
    private Environment env;
    /**
    * @Description:全部产品
    * @Author: zhengyunfei
    * @Date: 2018/10/30
    * @time:9:13
    */
    @PostMapping(value = "/all",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = ProductInfoContants.API_ALL,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object all(String productName,String pageNow){
        ResultModel resultModel=new ResultModel();
        try{
            int page=1;//默认首页
            if(!StringUtil.isNullOrEmpty(pageNow)&&StringUtil.isNumeric(pageNow)){
                page=Integer.parseInt(pageNow);
            }
            Map<String,Object> queryMap=new HashMap<>();
            queryMap.put("productName",productName);
            queryMap.put("pageNow",(page-1)*10+1);
            queryMap.put("pageSize",10*page);
            List<ProductInfoListForLiCaiShiBo> resultList=productInfoForLiCaiShiMapper.queryByListj(queryMap);
            resultModel.setData(resultList);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());

        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }
        Gson gson=new Gson();
        System.out.println(gson.toJson(resultModel));
        return resultModel;
    }
    /**
    * @Description: 按业绩基准查询产品
    * @Author: zhengyunfei
    * @Date: 2019/1/4
    * @time:10:31
    */
    @PostMapping(value = "/yjjz",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = ProductInfoContants.API_YJJZ,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object queryByProfit(String productName,String pageNow){
        ResultModel resultModel=new ResultModel();
        try{
            int page=1;//默认首页
            if(!StringUtil.isNullOrEmpty(pageNow)&&StringUtil.isNumeric(pageNow)){
                page=Integer.parseInt(pageNow);
            }
            Map<String,Object> queryMap=new HashMap();
            queryMap.put("productName",productName);
            queryMap.put("pageNow",(page-1)*10+1);
            queryMap.put("pageSize",10*page);
            List<ProductInfoListForLiCaiShiBo> productInfoList=productInfoForLiCaiShiMapper.queryByProfit(queryMap);
            resultModel.setData(productInfoList);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());

        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }

        return resultModel;
    }
    /**
     * @Description: 按投资期限查询所有产品
     * @Author: zhengyunfei
     * @Date: 2019/1/4
     * @time:10:31
     */
    @PostMapping(value = "/tzqx",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = ProductInfoContants.API_TZQX,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object queryByPermin(String productName,String pageNow){
        ResultModel resultModel=new ResultModel();
        try{
            int page=1;//默认首页
            if(!StringUtil.isNullOrEmpty(pageNow)&&StringUtil.isNumeric(pageNow)){
                page=Integer.parseInt(pageNow);
            }
            Map<String,Object> queryMap=new HashMap();
            queryMap.put("productName",productName);
            queryMap.put("pageNow",(page-1)*10+1);
            queryMap.put("pageSize",10*page);
            List<ProductInfoListForLiCaiShiBo> productInfoList=productInfoForLiCaiShiMapper.queryByPermin(queryMap);
            resultModel.setData(productInfoList);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());

        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }

        return resultModel;
    }
    /**
     * @Description: 按起投金额查询所有产品
     * @Author: zhengyunfei
     * @Date: 2019/1/4
     * @time:10:31
     */
    @PostMapping(value = "/tzMoney",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = ProductInfoContants.API_QTJE,notes = UserCenterContants.AUTHOR_NOTE,position = 1,response = ResultModel.class)
    @ResponseBody
    public Object queryByDeadline(String productName,String pageNow){
        ResultModel resultModel=new ResultModel();
        try{
            int page=1;//默认首页
            if(!StringUtil.isNullOrEmpty(pageNow)&&StringUtil.isNumeric(pageNow)){
                page=Integer.parseInt(pageNow);
            }
            Map<String,Object> queryMap=new HashMap();
            queryMap.put("productName",productName);
            queryMap.put("pageNow",(page-1)*10+1);
            queryMap.put("pageSize",10*page);
            List<ProductInfoListForLiCaiShiBo> productInfoList=productInfoForLiCaiShiMapper.queryByDeadline(queryMap);
            resultModel.setData(productInfoList);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());

        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
        }

        return resultModel;
    }
}
